package com.ruoyi.examination.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.examination.domain.ExamSchedule;
import com.ruoyi.examination.dto.PaperConfigDto;
import com.ruoyi.examination.vo.PaperConfigAddVo;
import com.ruoyi.examination.vo.PaperConfigSelectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.examination.domain.PaperConfig;
import com.ruoyi.examination.service.IPaperConfigService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 试卷信息设置Controller
 * 
 * @author hcc
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/paperConfig")
public class PaperConfigController extends BaseController
{
    @Autowired
    private IPaperConfigService paperConfigService;

    /**
     * 查询试卷信息设置列表
     */
    @RequiresPermissions("examination:paperConfig:list")
    @GetMapping("/list")
    public TableDataInfo list(PaperConfig paperConfig)
    {
        startPage();
        List<PaperConfig> list = paperConfigService.selectPaperConfigList(paperConfig);
        return getDataTable(list);
    }

    /**
     * 导出试卷信息设置列表
     */
    @RequiresPermissions("examination:paperConfig:export")
    @Log(title = "试卷信息设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaperConfig paperConfig)
    {
        List<PaperConfig> list = paperConfigService.selectPaperConfigList(paperConfig);
        ExcelUtil<PaperConfig> util = new ExcelUtil<PaperConfig>(PaperConfig.class);
        util.exportExcel(response, list, "试卷信息设置数据");
    }

    /**
     * 获取试卷信息设置详细信息
     */
    @RequiresPermissions("examination:paperConfig:query")
    @GetMapping(value = "/{paperConfigId}")
    public AjaxResult getInfo(@PathVariable("paperConfigId") String paperConfigId)
    {
        return success(paperConfigService.selectPaperConfigByPaperConfigId(paperConfigId));
    }

    /**
     * 新增试卷信息设置
     */
    @RequiresPermissions("examination:paperConfig:add")
    @Log(title = "试卷信息设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaperConfig paperConfig)
    {
        return toAjax(paperConfigService.insertPaperConfig(paperConfig));
    }

    /**
     * 修改试卷信息设置
     */
    @RequiresPermissions("examination:paperConfig:edit")
    @Log(title = "试卷信息设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaperConfig paperConfig)
    {
        return toAjax(paperConfigService.updatePaperConfig(paperConfig));
    }

    /**
     * 删除试卷信息设置
     */
    @RequiresPermissions("examination:paperConfig:remove")
    @Log(title = "试卷信息设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paperConfigIds}")
    public AjaxResult remove(@PathVariable String[] paperConfigIds)
    {
        return toAjax(paperConfigService.deletePaperConfigByPaperConfigIds(paperConfigIds));
    }

    /**
     * 新增试卷信息设置
     */
    @RequiresPermissions("examination:paperConfig:add")
    @Log(title = "试卷信息设置", businessType = BusinessType.INSERT)
    @PostMapping("/addPaperConfig")
    public AjaxResult addPaperConfig(@RequestBody PaperConfigAddVo paperConfigAddVo)
    {
        return toAjax(paperConfigService.addPaperConfig(paperConfigAddVo));
    }

    /**
     * 修改试卷信息设置
     */
    @RequiresPermissions("examination:paperConfig:edit")
    @Log(title = "试卷信息设置", businessType = BusinessType.UPDATE)
    @PutMapping("/editPaperConfig")
    public AjaxResult editPaperConfig(@RequestBody PaperConfigAddVo paperConfigAddVo)
    {
        return toAjax(paperConfigService.editPaperConfig(paperConfigAddVo));
    }

    /**
     * 查询试卷信息设置列表
     */
    @RequiresPermissions("examination:paperConfig:list")
    @GetMapping("/getList")
    public TableDataInfo getList(PaperConfigSelectVo paperConfigSelectVo)
    {
        startPage();
        List<PaperConfigDto> list = paperConfigService.getList(paperConfigSelectVo);
        return getDataTable(list);
    }

    /**
     * 获取试卷信息设置详细信息
     */
    @RequiresPermissions("examination:paperConfig:query")
    @GetMapping(value = "/getPaperConfigInfo/{paperConfigId}")
    public AjaxResult getPaperConfigInfo(@PathVariable("paperConfigId") String paperConfigId)
    {
        return success(paperConfigService.getPaperConfigInfo(paperConfigId));
    }

    /**
     * 根据试卷设置批量生成试卷
     */
    @RequiresPermissions("examination:paperConfig:query")
    @GetMapping(value = "/generatedPaper")
    public AjaxResult generatedPaper(@RequestBody ExamSchedule examSchedule)
    {
        return success(paperConfigService.generatedPaper(examSchedule));
    }

    /**
     * 逻辑删除试卷信息设置
     */
    @RequiresPermissions("examination:paperConfig:edit")
    @Log(title = "试卷信息设置", businessType = BusinessType.UPDATE)
    @PutMapping("/logicalRemove/{paperConfigIds}")
    public AjaxResult logicalRemove(@PathVariable String[] paperConfigIds)
    {
        return toAjax(paperConfigService.logicalRemove(paperConfigIds));
    }
}
